package com.freshfresh.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.text.SpannableString;
import android.text.style.StrikethroughSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.freshfresh.activity.R;
import com.freshfresh.activity.classification.ProductDetailsActivity;
import com.freshfresh.utils.ImageLoadOptions;
import com.freshfresh.utils.StringUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

public class IndexListThreeItem implements OnClickListener
  
{
  private Context context;
  private List<Map<String,Object>> proInfo;

  private Map<String,Object> getProInfo(int paramInt)
  {
    return (Map<String,Object>)this.proInfo.get(paramInt);
  }

  private void loadImg(final ImageView paramImageView, String paramString)
  {
    if ((paramString == null) || ("".equals(paramString)))
      return;
    ImageLoader.getInstance().displayImage(paramString, paramImageView, ImageLoadOptions.getOptions(0));
  }

  public View getView(Context paramContext, Map<String,Object> paramIndexProInfo)
  {
    this.context = paramContext;
    Map<String,Object> maps=(Map<String,Object>)paramIndexProInfo.get("product_list");
    this.proInfo =(List<Map<String,Object>>) maps.get("product_info");
    View localView = LayoutInflater.from(paramContext).inflate(R.layout.index_list_item4, null);
//    ((ImageView)localView.findViewById(R.id.iv_proTypeIcon)).setImageResource(paramIndexProInfo.getCategory_icon());
    LinearLayout localLinearLayout1 = (LinearLayout)localView.findViewById(R.id.ll_pro2);
    localLinearLayout1.setOnClickListener(this);
    localLinearLayout1.setTag(getProInfo(1).get("product_id") + "," + getProInfo(1).get("sku") + "," + paramIndexProInfo.get("categoryid"));
    LinearLayout localLinearLayout2 = (LinearLayout)localView.findViewById(R.id.ll_pro3);
    localLinearLayout2.setOnClickListener(this);
    localLinearLayout2.setTag(getProInfo(2).get("product_id") + "," + getProInfo(2).get("sku") + "," + paramIndexProInfo.get("categoryid"));
    ((TextView)localView.findViewById(R.id.tv_proType)).setText(paramIndexProInfo.get("category_name").toString());
    if(paramIndexProInfo.get("category_name")!=null){
	((TextView)localView.findViewById(R.id.tv_proTypeDes)).setText(paramIndexProInfo.get("category_name").toString());
    }
    
    TextView localTextView1 = (TextView)localView.findViewById(R.id.tv_more);
    localTextView1.setTag(paramIndexProInfo.get("categoryid").toString() + "," + paramIndexProInfo.get("category_name").toString());
//    localTextView1.setOnClickListener(this);
    ImageView localImageView = (ImageView)localView.findViewById(R.id.iv_pro1);
    loadImg(localImageView, getProInfo(0).get("appimage").toString());
    localImageView.setOnClickListener(this);
    localImageView.setTag(getProInfo(0).get("product_id") + "," + getProInfo(0).get("sku") + "," + paramIndexProInfo.get("categoryid"));
    
    
    
    
    
    Map<String,Object> localIndexProInfoListItem1 = getProInfo(1);
    loadImg((ImageView)localView.findViewById(R.id.iv_pro2), localIndexProInfoListItem1.get("image").toString());
    ((TextView)localView.findViewById(R.id.tv_proName2)).setText(localIndexProInfoListItem1.get("name").toString());
    ((TextView)localView.findViewById(R.id.tv_proPrice2)).setText(StringUtil.formatPrice("0.00", localIndexProInfoListItem1.get("special_price").toString()));
    TextView localTextView2 = (TextView)localView.findViewById(R.id.tv_proOriginalPrice2);
    String str1 = StringUtil.formatPrice(localIndexProInfoListItem1.get("price").toString());
    SpannableString localSpannableString1 = new SpannableString(str1);
    localSpannableString1.setSpan(new StrikethroughSpan(), 0, str1.length(), 33);
    localTextView2.setText(localSpannableString1);
    
    
    Map<String,Object> localIndexProInfoListItem2 = getProInfo(2);
    loadImg((ImageView)localView.findViewById(R.id.iv_pro3), localIndexProInfoListItem2.get("image").toString());
    ((TextView)localView.findViewById(R.id.tv_proName3)).setText(localIndexProInfoListItem2.get("name").toString());
    ((TextView)localView.findViewById(R.id.tv_proPrice3)).setText(StringUtil.formatPrice("0.00", localIndexProInfoListItem2.get("special_price").toString()));
    TextView localTextView3 = (TextView)localView.findViewById(R.id.tv_proOriginalPrice3);
    String str2 = StringUtil.formatPrice(localIndexProInfoListItem2.get("price").toString());
    SpannableString localSpannableString2 = new SpannableString(str2);
    localSpannableString2.setSpan(new StrikethroughSpan(), 0, str2.length(), 33);
    localTextView3.setText(localSpannableString2);
    return localView;
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    case R.id.iv_pro1:
    	 String[] arrayOfString1 = paramView.getTag().toString().split(",");
    	    Intent localIntent1 = new Intent(this.context, ProductDetailsActivity.class);
    	    localIntent1.putExtra("productid", arrayOfString1[0]);
    	    localIntent1.putExtra("sku", arrayOfString1[1]);
    	    localIntent1.putExtra("categoryid", arrayOfString1[2]);
    	    this.context.startActivity(localIntent1);
    	break;
    case R.id.ll_pro2:
    	 String[] arrayOfString2 = paramView.getTag().toString().split(",");
 	    Intent localIntent2 = new Intent(this.context, ProductDetailsActivity.class);
 	    localIntent2.putExtra("productid", arrayOfString2[0]);
 	    localIntent2.putExtra("sku", arrayOfString2[1]);
 	    localIntent2.putExtra("categoryid", arrayOfString2[2]);
 	    this.context.startActivity(localIntent2);
 	break;
    case R.id.ll_pro3:
    	 String[] arrayOfString3 = paramView.getTag().toString().split(",");
  	    Intent localIntent3 = new Intent(this.context, ProductDetailsActivity.class);
  	    localIntent3.putExtra("productid", arrayOfString3[0]);
  	  	localIntent3.putExtra("sku", arrayOfString3[1]);
  		localIntent3.putExtra("categoryid", arrayOfString3[2]);
  	    this.context.startActivity(localIntent3);
    	break;
    }
  }
}